<template>
  <view class="page-container">
    <!-- 顶部导航栏 -->
    <uni-nav-bar
      :border="false"
      title="提现"
      fixed
      left-icon="back"
      @clickLeft="goBack"
    />

    <!-- 提现表单 -->
    <view class="withdraw-form">
      <view class="form-section">
        <text class="section-label">提现金额</text>
        <view class="amount-input-wrapper">
          <input
            v-model="withdrawAmount"
            class="amount-input"
            type="digit"
            placeholder="请输入提现金额"
          />
          <text class="all-withdraw-btn" @click="withdrawAll">全部提现</text>
        </view>
      </view>

      <view class="balance-info">
        <text class="balance-label">备用金余额：</text>
        <text class="balance-value">¥ {{ reserveBalance }}</text>
      </view>

      <view class="account-info">
        <text class="account-text">提现到结算银行账户</text>
      </view>

      <view class="confirm-btn" @click="handleConfirm">
        <text>确定</text>
      </view>
    </view>

    <!-- 明细列表 -->
    <view class="detail-section">
      <view v-if="detailList.length > 0" class="detail-list">
        <view
          v-for="item in detailList"
          :key="item.id"
          class="detail-item"
          @click="handleDetailClick(item)"
        >
          <view class="detail-info">
            <text class="detail-type">{{ item.type }}</text>
            <text class="detail-time">{{ item.time }}</text>
          </view>
          <view class="detail-right">
            <text class="detail-amount">¥ {{ item.amount }}</text>
            <uni-icons type="right" size="16" color="#999"></uni-icons>
          </view>
        </view>
      </view>

      <!-- 空状态 -->
      <view v-else class="empty-state">
        <view class="empty-icon">
          <uni-icons type="list" size="80" color="#d9d9d9"></uni-icons>
        </view>
        <text class="empty-text">暂无数据~</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";

// 提现金额
const withdrawAmount = ref("");

// 备用金余额
const reserveBalance = ref("0.00");

// 明细列表
const detailList = ref([]);

// 返回上一页
const goBack = () => {
  uni.navigateBack();
};

// 全部提现
const withdrawAll = () => {
  withdrawAmount.value = reserveBalance.value;
};

// 确认提现
const handleConfirm = () => {
  if (!withdrawAmount.value || parseFloat(withdrawAmount.value) <= 0) {
    uni.showToast({
      title: "请输入有效金额",
      icon: "none",
    });
    return;
  }

  const amount = parseFloat(withdrawAmount.value);
  const balance = parseFloat(reserveBalance.value);

  if (amount > balance) {
    uni.showToast({
      title: "提现金额不能大于余额",
      icon: "none",
    });
    return;
  }

  console.log("提现金额:", amount);

  uni.showToast({
    title: `提现成功：¥${amount}`,
    icon: "none",
  });

  // TODO: 调用提现接口
  // TODO: 刷新数据
};

// 处理明细点击
const handleDetailClick = (item) => {
  console.log("点击明细:", item);
  // TODO: 跳转到明细详情
};

onMounted(() => {
  console.log("提现页面加载完成");
  // TODO: 加载备用金余额数据
});
</script>

<style lang="scss" scoped>
.page-container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

// 提现表单
.withdraw-form {
  background-color: #fff;
  margin: 20rpx 30rpx;
  padding: 40rpx 30rpx;
  border-radius: 16rpx;
}

.form-section {
  margin-bottom: 30rpx;
}

.section-label {
  display: block;
  font-size: 28rpx;
  color: #333;
  font-weight: 600;
  margin-bottom: 20rpx;
}

.amount-input-wrapper {
  display: flex;
  align-items: center;
  gap: 20rpx;
}

.amount-input {
  flex: 1;
  height: 80rpx;
  padding: 0 20rpx;
  background-color: #f5f5f5;
  border-radius: 8rpx;
  font-size: 28rpx;
  color: #333;
  border: 1rpx solid transparent;

  &:focus {
    border-color: #ffb200;
    background-color: #fff;
  }
}

.all-withdraw-btn {
  font-size: 28rpx;
  color: #ffb200;
  white-space: nowrap;

  &:active {
    opacity: 0.7;
  }
}

.balance-info {
  display: flex;
  align-items: center;
  margin-bottom: 30rpx;
}

.balance-label {
  font-size: 26rpx;
  color: #666;
}

.balance-value {
  font-size: 26rpx;
  color: #333;
  font-weight: 500;
}

.account-info {
  margin-bottom: 40rpx;
}

.account-text {
  font-size: 24rpx;
  color: #999;
}

.confirm-btn {
  width: 100%;
  height: 88rpx;
  background-color: #ffb200;
  border-radius: 50rpx;
  display: flex;
  align-items: center;
  justify-content: center;

  text {
    font-size: 32rpx;
    font-weight: 600;
    color: #333;
  }

  &:active {
    opacity: 0.8;
  }
}

// 明细列表
.detail-section {
  margin: 20rpx 30rpx;
}

.detail-list {
  background-color: #fff;
  border-radius: 12rpx;
  overflow: hidden;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24rpx 30rpx;
  border-bottom: 1rpx solid #f0f0f0;

  &:last-child {
    border-bottom: none;
  }

  &:active {
    background-color: #f9f9f9;
  }
}

.detail-info {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.detail-type {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.detail-time {
  font-size: 24rpx;
  color: #999;
}

.detail-right {
  display: flex;
  align-items: center;
  gap: 12rpx;
}

.detail-amount {
  font-size: 32rpx;
  font-weight: 600;
  color: #333;
}

// 空状态
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 120rpx 0;
  background-color: #fff;
  border-radius: 12rpx;
}

.empty-icon {
  margin-bottom: 20rpx;
}

.empty-text {
  font-size: 28rpx;
  color: #999;
}
</style>
